package com.lrkj.back.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.lrkj.back.mapper.TbProductMapper;
import com.lrkj.back.service.TbProductService;
import com.lrkj.back.entity.TbProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.com.cbons.mamisay.parent.db.api.DBInterface;
import cn.com.cbons.mamisay.parent.exception.DBException;
import cn.com.cbons.mamisay.parent.service.base.ParentServiceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Transactional
@Service("product")
public class TbProductServiceImpl extends ParentServiceImpl<TbProduct> implements TbProductService {

    @Autowired
    private TbProductMapper tbProductMapper;

    @Override
    protected DBInterface<TbProduct> getDao() throws DBException {
        return tbProductMapper;
    }

    @Override
    public List<TbProduct> findAllProduct() throws DBException {
        Map<String, Object> map = new HashMap<String, Object>();
        return tbProductMapper.findAllProduct(map);
    }

    @Override
    public List<TbProduct> findAllProducts(Map<String, Object> map) throws DBException {
        return tbProductMapper.findAllProduct(map);
    }

    @Override
    public PageInfo<TbProduct> findAllProductList(Map<String, Object> map) throws DBException {
        PageHelper.startPage(Integer.valueOf(map.get("pageNo").toString()),
                Integer.valueOf(map.get("pageSize").toString()));
        List<TbProduct> productList = tbProductMapper.findAllProduct(map);
        PageInfo<TbProduct> page = new PageInfo<>(productList);
        return page;
    }

    @Override
    public List<TbProduct> findAllProductByTypeId(Integer protypeId) throws DBException {
        List<TbProduct> productList = tbProductMapper.findAllProductByTypeId(protypeId);
        return productList;
    }

    public List<TbProduct> findQixieByPackage(Map<String, Object> map) throws DBException {
        List<TbProduct> list = tbProductMapper.selectByPackageId(map);
        return list;

    }

    @Override
    public PageInfo<TbProduct> findQixieByPackagePage(Map<String, Object> map) throws DBException {
        PageHelper.startPage(Integer.valueOf(map.get("pageNo").toString()),
                Integer.valueOf(map.get("pageSize").toString()));
        List<TbProduct> list = tbProductMapper.selectByPackageId(map);
        PageInfo<TbProduct> page = new PageInfo<TbProduct>(list);
        return page;
    }

}
